﻿/* 6. Write a program that reads the coefficients a, b and c of a quadratic equation ax^2+bx+c=0 
 * and solves it (prints its real roots). */

using System;

public class QuadraticEquation
{
    public static void Main()
    {
        decimal a;
        decimal b;
        decimal c;
        double D;

        Console.WriteLine("a*x*x + b*x + c = 0 when");
        Console.Write("a = ");
        a = decimal.Parse(Console.ReadLine());
        Console.Write("b = ");
        b = decimal.Parse(Console.ReadLine());
        Console.Write("c = ");
        c = decimal.Parse(Console.ReadLine());
                            
        if (a != 0)
        {
            D = (double)(b * b - 4 * a * c);
            if (D > 0)
                Console.WriteLine("there is two different real roots\nx1 = {0} and\nx2 = {1}",
                    ((-1M) * b - (decimal)Math.Sqrt(D)) / (2 * a), ((-1M) * b + (decimal)Math.Sqrt(D)) / (2 * a));
            else if (D < 0)
                Console.WriteLine("there isn't real root");
            else
                Console.WriteLine("there is a double real root\nx = {0}", (-1M) * b / (2 * a));
        }
        else
            if (b == 0)
                if (c == 0)
                    Console.WriteLine("every real number is a root");
                else
                    Console.WriteLine("there isn't real root");
            else
                Console.WriteLine("there is unique real root\nx = {0}", (-1M) * c / b);
    }
}